package cn.wangqi.personal.dao;

import cn.wangqi.personal.domain.Major;
import cn.wangqi.personal.util.Page;
import org.apache.log4j.Logger;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 *created by admin  2017-09-11 06:21:44
 */
@Repository
public class MajorDao{
    private final String NAMESPACE = this.getClass().getName() + ".";
    private Logger logger = Logger.getLogger(MajorDao.class);
    @Resource
    protected SqlSessionTemplate mainSqlSession;
    public void saveMajor(Major major) {
        mainSqlSession.insert(NAMESPACE + "saveMajor", major);
    }

    public void deleteMajorById(int majorId) {
        mainSqlSession.delete(NAMESPACE + "deleteMajorById", majorId);
    }

    public Major findMajorById(int majorId){
        return mainSqlSession.selectOne(NAMESPACE + "findMajorById", majorId);
    }

    public List<Major> listMajor(Integer collageId, Page page){
        Map<String, Object> params = new HashMap<>();
        params.put("page",page);
        params.put("collageId",collageId);
        return mainSqlSession.selectList(NAMESPACE + "listMajor", params);
    }

    public int countMajor(Integer collageId){
        Map<String, Object> params = new HashMap<>();
        params.put("collageId",collageId);
        return mainSqlSession.selectOne(NAMESPACE + "countMajor",params);
    }

    public void updateMajor(Major major){
        mainSqlSession.update(NAMESPACE + "updateMajor", major);
    }

}
